package com.tale.springbootatm.common.rabbit;

import com.tale.springbootatm.common.constant.RabbitConstant;
import com.tale.springbootatm.common.vo.MessageVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 生产者：发送消息到队列
 *
 * author: 蔡奇峰
 * date: 2020/5/2 12:55
 **/
@Slf4j
@Component
public class RabbitSender {

    @Autowired
    private RabbitTemplate rabbitTemplate;


    /**
     *
     * @param msg 当前用户对象修改消息
     */
    public void send(MessageVO msg){
        CorrelationData correlationData = new CorrelationData(System.currentTimeMillis() + "");

        rabbitTemplate.convertAndSend(RabbitConstant.MAIL_EXCHANGE, RabbitConstant.MAIL_ROUTE_KEY, msg, correlationData);

        log.info("发送消息......");
    }

}
